package com.itheima.test1;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Author:gy
 * @Date: 2025/08/28 9:40
 * @Description:
 */
public class Demo1 {
    public static void main(String[] args) {
        //创建一个字节输出流关联文件
        //File file = new File("D:\\班级\\93期\\day10-IO\\day10-IO\\a.txt");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(new File("D:\\班级\\93期\\day10-IO\\day10-IO\\a.txt"), true);
            //写数据
            byte[] bytes = {97, 98, 99, 100, 101, 102, 103, 104, 105};
            //从off索引开始  写len个
            fos.write(bytes, 1, 2);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            //关流  释放资源
            if(fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
